const webpack = require('webpack')
const { merge } = require('webpack-merge')
const commonWebpackConfig = require('./webpack.common')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin')

const path = require('path')
module.exports = merge(commonWebpackConfig, {
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'js/[name][hash:8].js',
    chunkFilename: 'js/[name][hash:8].chunk.js',
    publicPath: './'
  },
  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin(),
    new OptimizeCssAssetsWebpackPlugin(),

    new HtmlWebpackPlugin({
      title: 'vue',
      inject: true,
      template: path.resolve(__dirname, 'public/index.html'),
      templateParameters: {
        BASE_URL: './'
      },
      minify: {
        removeComments: true, // 移除注释
        collapseWhitespace: true, // 去除空格
        removeEmptyAttributes: true // 去除空属性
      }
    })
  ],
  devtool: 'source-map'
})
